﻿<%@ Page AutoEventWireup="true" CodeBehind="Manage.aspx.cs" Inherits="AssetManage.Manage.Manage" Language="C#" MasterPageFile="~/Site.Master" Title="交易管理" %>

<%@ Register Assembly="Trirand.Web" Namespace="Trirand.Web.UI.WebControls" TagPrefix="cc1" %>

<%@ MasterType VirtualPath="~/Site.Master" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <link type="text/css" href="/Content/trirand/ui.jqgrid.css" rel="stylesheet"/>
    <link type="text/css" href="/Content/trirand/jqGrid.overrides.css" rel="stylesheet"/>
    <link type="text/css" href="/Content/trirand/ui.jqautocomplete.css" rel="stylesheet"/>
    <style>
        .ui-jqgrid .ui-jqgrid-htable th {
            font-size: medium;
            font-weight: 700;
            height: 32px;
            padding-bottom: 15px;
        }

        .ui-jqgrid .ui-pg-selbox { width: 55px; }

        .ui-jqgrid .ui-pg-input { width: 20px; }
    </style>

    <script type="text/javascript" src="/Scripts/trirand/i18n/grid.locale-cn.js"></script>
    <script type="text/javascript" src="/Scripts/trirand/jquery.jqGrid.min.js"></script>
    <script type="text/javascript" src="/Scripts/trirand/jquery.jqDatePicker.min.js"></script>
    <script type="text/javascript" src="/Scripts/trirand/jquery.jqAutoComplete.min.js"></script>
    <script type="text/javascript">
        var Balance = "#<%= Balance.ClientID %>";
        var UserID = "#<%= UserID.ClientID %>";
        $(function() {
            $("#Expense_Div").bind("DOMNodeInserted", function(e) {
                if ($(e.target).html() === "<td role=\"gridcell\" style=\"height:0px;width:72px;\"></td><td role=\"gridcell\" style=\"height:0px;width:150px;\"></td><td role=\"gridcell\" style=\"height:0px;width:75px;\"></td><td role=\"gridcell\" style=\"height:0px;width:205px;\"></td>") {
                    GetBalance();
                }
            });
        });

        function GetBalance() {
            var sendData = {
                "action": "balance",
                "tableid": $(UserID).val()
            };
            $.ajax({
                type: "POST",
                url: "/Handler/Account",
                data: sendData,
                success: function(response) {
                    var responseData = eval("(" + response + ")");
                    if (responseData.success) {
                        $(Balance).val(responseData.balance);
                        $(Balance).css("color", responseData.color);
                    }
                }
            });
        }
    </script>

    <div class="form-horizontal">
        <h3>账户交易记录</h3>
        <hr/>
        <div class="form-group">
            <asp:Label runat="server" AssociatedControlID="UserID" CssClass="col-md-2 control-label">账户</asp:Label>
            <div class="col-md-10">
                <asp:DropDownList ID="UserID" CssClass="form-control" runat="server" Font-Size="Medium" DataSourceID="Account_SqlDataSource" DataTextField="RealName" DataValueField="TableID" OnDataBound="UserID_DataBound" AutoPostBack="True" OnSelectedIndexChanged="UserID_SelectedIndexChanged">
                </asp:DropDownList>
                <asp:SqlDataSource ID="Account_SqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:Account_ConnectionString %>" ProviderName="<%$ ConnectionStrings:Account_ConnectionString.ProviderName %>" SelectCommand="SELECT [TableID], [RealName] FROM [Account] WHERE ([TableID] &lt;&gt; 'Administrator')"></asp:SqlDataSource>
            </div>
        </div>
        <div class="form-group">
            <asp:Label runat="server" AssociatedControlID="Balance" CssClass="col-md-2 control-label">账户余额</asp:Label>
            <div class="col-md-10" runat="server">
                <asp:TextBox runat="server" ID="Balance" CssClass="form-control" Font-Size="Medium" Nullable="False" TextMode="Number" ReadOnly="True" Style="cursor: text"/>
            </div>
        </div>
        <div class="form-group">
            <asp:Label runat="server" AssociatedControlID="Expense" CssClass="col-md-2 control-label">交易记录</asp:Label>
            <div id="Expense_Div" class="col-md-10">
                <cc1:JQGrid ID="Expense" runat="server" DataSourceID="Expense_SqlDataSource" Width="520px" Height="365px" AutoEncode="True">
                    <Columns>
                        <cc1:JQGridColumn
                            HeaderText="流水号"
                            DataField="ID"
                            TextAlign="Right"
                            Width="60"
                            PrimaryKey="True">
                        </cc1:JQGridColumn>
                        <cc1:JQGridColumn
                            HeaderText="时间"
                            DataField="Time"
                            TextAlign="Left"
                            DataFormatString="{0:yyyy-MM-dd HH:mm:ss}"
                            FixedWidth="true"
                            Width="150">
                        </cc1:JQGridColumn>
                        <cc1:JQGridColumn
                            HeaderText="金额"
                            DataField="Expense"
                            TextAlign="Right"
                            Editable="true"
                            DataFormatString="{0:N2}"
                            FixedWidth="true"
                            Width="75">
                        </cc1:JQGridColumn>
                        <cc1:JQGridColumn
                            HeaderText="项目"
                            DataField="Item"
                            TextAlign="Left"
                            Editable="true"
                            FixedWidth="true"
                            Width="205" Sortable="False">
                        </cc1:JQGridColumn>
                    </Columns>
                    <SortSettings
                        InitialSortColumn="Time"
                        InitialSortDirection="Desc"/>
                    <ToolBarSettings
                        ShowAddButton="true"
                        ShowDeleteButton="true"
                        ShowEditButton="true"
                        ShowViewRowDetailsButton="true"
                        ToolBarPosition="Bottom"/>
                </cc1:JQGrid>
                <asp:SqlDataSource ConnectionString="<%$ ConnectionStrings:Expense_ConnectionString %>" DeleteCommand="DELETE FROM [Public] WHERE [ID] = @ID" ID="Expense_SqlDataSource" InsertCommand="INSERT INTO [Public] ([Time], [Expense], [Item]) VALUES (Now(), @Expense, @Item)" ProviderName="<%$ ConnectionStrings:Expense_ConnectionString.ProviderName %>" runat="server" SelectCommand="SELECT * FROM [Public] ORDER BY [Time] DESC" UpdateCommand="UPDATE [Public] SET [Expense] = @Expense, [Item] = @Item WHERE [ID] = @ID">
                    <DeleteParameters>
                        <asp:Parameter Name="ID" DbType="Int32"/>
                    </DeleteParameters>
                    <InsertParameters>
                        <asp:Parameter Name="Expense" DbType="Currency"/>
                        <asp:Parameter Name="Item" DbType="String"/>
                    </InsertParameters>
                    <UpdateParameters>
                        <asp:Parameter Name="Expense" DbType="Currency"/>
                        <asp:Parameter Name="Item" DbType="String"/>
                        <asp:Parameter Name="ID" DbType="Int32"/>
                    </UpdateParameters>
                </asp:SqlDataSource>
            </div>
        </div>
    </div>
</asp:Content>